﻿<Window
             xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
             xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
             xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" 
             xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
             xmlns:attachmentHandler="clr-namespace:AttachmentHandler"
             xmlns:Converters="clr-namespace:AttachmentHandler.Converters" x:Class="AttachmentHandler.SettingsWindow"
             mc:Ignorable="d" 
             d:DataContext="{d:DesignInstance {x:Type attachmentHandler:SettingsWindow}}" 
             d:DesignHeight="300" d:DesignWidth="400" Title="Attachment Handler Settings" Width="400" Height="300" WindowStartupLocation="CenterScreen" ResizeMode="NoResize" >
    <Window.Resources>
        <Converters:FolderToStringConverter x:Key="FolderToStringConverter"/>
        <Style TargetType="{x:Type Label}">
            <Setter Property="Margin" Value="5,0,5,0" />
            <Setter Property="HorizontalAlignment" Value="Left" />
        </Style>
        <Style TargetType="{x:Type TextBox}">
            <Setter Property="VerticalAlignment" Value="Center" />
            <Setter Property="Margin" Value="0,2,40,2" />
            <Setter Property="Validation.ErrorTemplate">
                <Setter.Value>
                    <ControlTemplate>
                        <DockPanel LastChildFill="true">
                            <Border Background="OrangeRed" DockPanel.Dock="right" Margin="5,0,0,0" Width="20" Height="20" CornerRadius="5" ToolTip="{Binding AdornedElement.(Validation.Errors)[0].ErrorContent, ElementName=customAdorner}">
                                <TextBlock Text="!" VerticalAlignment="center" HorizontalAlignment="center" 
                                   FontWeight="Bold" Foreground="white" />
                            </Border>
                            <AdornedElementPlaceholder x:Name="customAdorner" VerticalAlignment="Center" >
                                <Border BorderBrush="red" BorderThickness="1" />
                            </AdornedElementPlaceholder>
                        </DockPanel>
                    </ControlTemplate>
                </Setter.Value>
            </Setter>
        </Style>
    </Window.Resources>
    <Grid>
        <Grid.CommandBindings>
            <CommandBinding Command="Save" CanExecute="ConfirmCanExecute" Executed="ConfirmExecuted" />
        </Grid.CommandBindings>
        <StackPanel>
            <GroupBox Header="Source Folder" Margin="5,0">
                <Grid Margin="5,5,5,0">
                    <Button Content="..." HorizontalAlignment="Right" VerticalAlignment="Center" Width="30" Click="SourceButtonClick" Margin="0"/>
                    <TextBox TextWrapping="Wrap" Validation.Error="ValidationError" Text="{Binding Settings.SourceFolder, Converter={StaticResource FolderToStringConverter}, NotifyOnValidationError=True, ValidatesOnDataErrors=True}" Margin="0,0,60,0" IsReadOnly="True"/>
                </Grid>
            </GroupBox>
            <GroupBox Header="Destination Folder" Margin="5,5,5,0">
                <Grid Margin="5,5,5,0">
                    <Button Content="..." HorizontalAlignment="Right" VerticalAlignment="Center" Width="30" Margin="0" Click="DestinationButtonClick" MouseRightButtonUp="ButtonMouseRightButtonUp"/>
                    <TextBox TextWrapping="Wrap" Validation.Error="ValidationError" Text="{Binding Settings.DestinationFolder, Mode=OneWay, ValidatesOnDataErrors=true, NotifyOnValidationError=true}" Margin="0,0,60,0" IsReadOnly="True"/>
                </Grid>
            </GroupBox>
            <Separator Margin="10"/>
            <GroupBox Header="Miscellaneous" Margin="5,0">
                <StackPanel Margin="0">
                    <CheckBox Content="Only process unread mails" Margin="0,5,0,0" IsChecked="{Binding Settings.OnlyUnread}"/>
                    <CheckBox Content="Mark mails as read after processing" Margin="0,5,0,0" IsChecked="{Binding Settings.MarkAsRead}"/>
                </StackPanel>
            </GroupBox>
        </StackPanel>
        <Button Content="Save Settings &amp; Close..." HorizontalAlignment="Center" VerticalAlignment="Bottom" Width="150" Margin="0,0,0,10" Command="Save"/>

    </Grid>
</Window>
